﻿using System;
using System.Linq;
using System.Linq.Expressions;

namespace SimpleORM
{
    public class DeleteTranslator : LambdaTranslator
    {
        #region Properties

        #endregion

        #region Methods

        #region Methods - Public

        public override void Translate(Expression expression)
        {
            IScriptFactory f = DataSource.CreateScriptFactory();

            MethodCallExpression m = expression as MethodCallExpression;

            if (m.Arguments.Count == 1)
            {
                Result = f.Constant(FromNameDictionary.Get(((
                           m.FindFirst().Arguments[0] as ConstantExpression).Value as IQueryable).ElementType)).
                           Stress();

            }
            else
            {
                var oc = ObjectContextDictionary.Get((
                    m.Arguments[1] as ConstantExpression).Value as Type);

                Result = f.SchemaObject(oc.Schema, oc.TableName);
            }
        }

        #endregion

        #endregion
    }
}
